<!--处分-->
<template>
  <div class="form">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left" class="label required">处分时间</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择处分时间'}]"
          v-model="form.punishmentDate"
          ref="punishmentDate"
          placeholder="请选择处分时间"
          :endDate="new Date()"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">处分名称</span>
        <xf-picker
          slot="right"
          :valid="[{required: true, msg: '请选择处分名称'}]"
          v-model="form.punishmentCode"
          :text.sync="form.punishmentName"
          ref="punishmentCode"
          :list="punish"
          placeholder="请选择处分名称"></xf-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">处分批准单位</span>
        <xf-input
          :valid="[{required: true, msg: '请填写处分批准单位'}]"
          v-model="form.punishmentCompanyName"
          ref="punishmentCompanyName"
          slot="right"
          placeholder="请填写处分批准单位"></xf-input>
      </yd-cell-item>
    </yd-cell-group>
    <div class="right-bottom">
      <mt-button type="default" size="small" @click="cancel">取消</mt-button>
      <mt-button type="primary" size="small" @click="onSubmit">保存</mt-button>
    </div>
  </div>
</template>
<script>
  import XfDatePicker from '../../../components/xf-date-picker/xf-date-picker.vue'
  import XfInput from '../../../components/xf-input/xf-input.vue'
  import {dics, getDics} from '../../../common/js/dictionaries'
  import XfPicker from '../../../components/xf-picker/xf-picker'
  import {echo, validate} from '../../../common/js/util'

  export default {
    props: {
      detail: {type: null, default: () => { return {} }}
    },
    components: {
      XfPicker,
      XfInput,
      XfDatePicker},
    name: 'roll-in-award-form',
    data() {
      return {
        form: {
          id: '',
          punishmentDate: '', // 奖励时间
          punishmentCode: '', // 奖励名称代码
          punishmentCompanyName: '', // 奖励批准单位名称
          punishmentName: '' // 奖励名称
        },
        punish: []
      }
    },
    methods: {
      cancel() {
        this.$emit('cancel')
      },
      onSubmit() {
        validate.bind(this)(this.form).then(() => {
          const form = Object.assign({}, this.form)
          form.personId = this.$route.query.id
          form.type = 2
          this.$post('/admin/person/sapi/party/reward/punishment/update', form).then(res => {
            this.$emit('save')
          })
        })
      },
      getDics() {
        getDics(dics.punish).then(res => {
          this.punish = res[0]
        })
      }
    },
    created() {
      this.getDics()
      echo(this.form, this.detail)
    }
  }
</script>
<style scoped lang="scss">
  @import "../../../common/style/variable";
  .img-box{
    width: 100%;
    padding: .2rem .2rem;
    display: flex;
    .upload-img{
      width: 2rem;
    }
  }
</style>
